/* GUI CONVERTED from rectmt.p (converter v1.76) Wed May 22 11:22:35 2002 */
/* rectmt.p - REPETITIVE   SUBCONTRACT CONTAINER MAINT                        */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.9.3.6 $                                                       */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN77*                */
/* REVISION: 7.3      LAST MODIFIED: 11/03/94   BY: WUG *GN98*                */
/* REVISION: 8.5      LAST MODIFIED: 05/12/95   BY: pma *J04T*                */
/* REVISION: 8.5      LAST MODIFIED: 10/04/96   BY: *G2GK* Murli Shastri      */
/* REVISION: 8.6      LAST MODIFIED: 04/09/97   BY: *K08N* Steve Goeke        */
/* REVISION: 8.6      LAST MODIFIED: 12/29/97   BY: *J28S* Seema Varma        */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 08/18/99   BY: *K223* Santosh Rao        */
/* REVISION: 9.1      LAST MODIFIED: 10/25/99   BY: *N002* Bill Gates         */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb                */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.9.3.6 $   BY: Jean Miller        DATE: 05/20/02  ECO: *P05V*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdtitle.i "2+ "}

define new shared variable so_db like dc_name.
define new shared variable old_site like si_site.
define new shared variable new_site like si_site.
define new shared variable err_stat as integer.
define new shared variable h_wiplottrace_procs as handle no-undo.
define new shared variable h_wiplottrace_funcs as handle no-undo.

define shared variable global_recid as recid.

define variable disp_abs_id like abs_id.
define variable abs_recid as recid.
define variable del-yn like mfc_logical.
define variable deassign like mfc_logical.
define variable old_gwt like pt_net_wt.
define variable old_nwt like pt_net_wt.
define variable old_vol like abs_vol.
define variable diff_gwt like pt_net_wt.
define variable diff_nwt like pt_net_wt.
define variable diff_vol like abs_vol.
define variable wt_conv as decimal.
define variable vol_conv as decimal.
define variable nullstr as character.
define variable ship_db as character.
define variable disp_id as character.
define variable transtype as character initial "ISS-UNP".
define variable undotran like mfc_logical no-undo.

define buffer abs_mstr_cont for abs_mstr.
define buffer abs_mstr_par for abs_mstr.

{wlfnc.i} /*FUNCTION FORWARD DECLARATIONS*/

if is_wiplottrace_enabled() then do:
   {gprunmo.i &program=""wlpl.p"" &module="AWT"
      &persistent="""persistent set h_wiplottrace_procs"""}
   {gprunmo.i &program=""wlfl.p"" &module="AWT"
      &persistent="""persistent set h_wiplottrace_funcs"""}
end.


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
abs_shipfrom         colon 20 label "Ship-From Site"
   si_desc              at 45 no-label
   abs_id               colon 20 label "Container ID"
   format "x(8)"
 SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
abs_shipto           colon 20 label "Ship-To"
   ad_name              at 45 no-label
   ad_line1             at 45 no-label
 SKIP(.4)  /*GUI*/
with frame b side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-b-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame b = F-b-title.
 RECT-FRAME-LABEL:HIDDEN in frame b = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame b =
  FRAME b:HEIGHT-PIXELS - RECT-FRAME:Y in frame b - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME b = FRAME b:WIDTH-CHARS - .5.  /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame b:handle).

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
abs_item             colon 20
   pt_desc1             at 45 no-label
   abs_qty              colon 20 format "->,>>>,>>9.9<<<<<<<<"
   abs_site             colon 20
   abs_loc              colon 20
   loc_desc             at 45 no-label
   abs_lotser           colon 20
   abs_ref              colon 20
 SKIP(.4)  /*GUI*/
with frame c side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-c-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame c = F-c-title.
 RECT-FRAME-LABEL:HIDDEN in frame c = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame c =
  FRAME c:HEIGHT-PIXELS - RECT-FRAME:Y in frame c - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME c = FRAME c:WIDTH-CHARS - .5.  /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame c:handle).

find mfc_ctrl where mfc_field = "rpc_using_new" no-lock no-error.
if not available mfc_ctrl or mfc_logical = false then do:
   /* This module has not been enabled in Contol file Maintenance */
   {pxmsg.i &MSGNUM=5119 &ERRORLEVEL=3}
   message.
   message.
   leave.
end.

find abs_mstr where recid(abs_mstr) = global_recid no-lock no-error.

if available abs_mstr and abs_id begins "c"
   and abs_type = "u"
then do:
   find si_mstr where si_site = abs_shipfrom no-lock.
   display
      abs_shipfrom
      si_desc
      substring(abs_id,2,8) @ abs_id
   with frame a.
end.

so_db = global_db.

{gprun.i ""rcpma.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


mainloop:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.


   do transaction with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.


      prompt-for
         abs_shipfrom abs_id
      editing:
         global_site = input abs_shipfrom.

         if frame-field = "abs_shipfrom" then do:

            {mfnp05.i abs_mstr abs_id
               "abs_id begins ""c"" and
                 abs_type = ""u"" "
               abs_shipfrom
               "input abs_shipfrom" }

            if recno <> ? then do:
               find si_mstr where si_site = abs_shipfrom
               no-lock no-error.

               assign
                  disp_abs_id = substring(abs_id,2,8).

               display
                  abs_shipfrom
                  si_desc  when (available si_mstr)
                  ""       when (not available si_mstr) @ si_desc
                  disp_abs_id @ abs_id.
            end.

         end.

         else
         if frame-field = "abs_id" then do:

            {mfnp05.i abs_mstr abs_id
               "abs_shipfrom = input abs_shipfrom and
                 abs_id begins ""c"" and
                 abs_type = ""u"" "
               abs_id
               " ""c"" + input abs_id" }

            if recno <> ? then do:
               find si_mstr where si_site = abs_shipfrom
               no-lock no-error.

               assign
                  disp_abs_id = substring(abs_id,2,8).

               display
                  abs_shipfrom
                  si_desc  when (available si_mstr)
                  ""       when (not available si_mstr) @ si_desc
                  disp_abs_id @ abs_id.

            end.

         end.

         else do:
            status input.
            readkey.
            apply lastkey.
         end.

      end.

      find si_mstr where si_site = input abs_shipfrom
      no-lock no-error.

      if not available si_mstr then do:
         {pxmsg.i &MSGNUM=708 &ERRORLEVEL=3}
         next-prompt abs_shipfrom.
         undo, retry.
      end.

      {gprun.i ""gpsiver.p""
         "(input si_site, input recid(si_mstr), output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      if return_int = 0 then do:
         {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
         /* USER DOES NOT HAVE ACCESS TO THIS SITE */
         next-prompt abs_shipfrom.
         undo mainloop, retry.
      end.

      display si_desc.

      if input abs_id = "" then do:

         find mfc_ctrl where mfc_field = "rcc_next_ctnr"
         exclusive-lock.

         do while can-find(abs_mstr where
                           abs_shipfrom = input abs_shipfrom
                       and abs_id = "c" + string(mfc_integer,"99999999")):
            mfc_integer = mfc_integer + 1.
            if mfc_integer >= 100000000 then mfc_integer = 1.
         end.

         display
            string(mfc_integer,"99999999") @ abs_id.

         mfc_integer = mfc_integer + 1.
         if mfc_integer >= 100000000 then mfc_integer = 1.

      end.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.


   release mfc_ctrl.

   do transaction:
/*GUI*/ if global-beam-me-up then undo, leave.


      find abs_mstr where abs_shipfrom = input frame a abs_shipfrom
                      and abs_id = "c" + input frame a abs_id
      exclusive-lock no-error.

      if not available abs_mstr then do:

         /* Adding Record */
         {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}

         create abs_mstr.
         assign
            abs_shipfrom = input frame a abs_shipfrom
            abs_id = "c" + input frame a abs_id.

         assign
            abs_qty = 1
            abs_shp_date = today
            abs_type = "u".
      end.

      else do:
         if abs_type <> "u" then do:
            /* Not a subcontract container */
            {pxmsg.i &MSGNUM=5105 &ERRORLEVEL=3}
            undo mainloop, retry mainloop.
         end.
      end.

      find ad_mstr where ad_addr = abs_shipto no-lock no-error.

      clear frame b.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame b = F-b-title.

      display
         abs_shipto
         ad_name      when (available ad_mstr)
         ad_line1     when (available ad_mstr)
      with frame b.

      do for abs_mstr_par:
         find abs_mstr_par
            where abs_mstr_par.abs_shipfrom = abs_mstr.abs_shipfrom
            and abs_mstr_par.abs_id = abs_mstr.abs_par_id
         no-lock no-error.
         if available abs_mstr_par then do:
            /* This is subordinate to # */
            {pxmsg.i &MSGNUM=8102 &ERRORLEVEL=1 &MSGARG1=abs_id}
         end.
      end.

      if can-find(first abs_mstr_cont
         where abs_mstr_cont.abs_shipfrom = abs_mstr.abs_shipfrom
         and abs_mstr_cont.abs_par_id = abs_mstr.abs_id)
         or can-find(abs_mstr_cont
         where abs_mstr_cont.abs_shipfrom = abs_mstr.abs_shipfrom
         and abs_mstr_cont.abs_par_id = abs_mstr.abs_id)
      then do:
         /* Contents (container or item) exist */
         {pxmsg.i &MSGNUM=8103 &ERRORLEVEL=1}
      end.

      else do on error undo, retry
              on endkey undo mainloop,
         retry mainloop with frame b:
/*GUI*/ if global-beam-me-up then undo, leave.

         {reshmta.i}
      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      ststatus = stline[3].
      status input ststatus.

      find pt_mstr where pt_part = abs_item no-lock no-error.

      display
         abs_item
         pt_desc1  when (available pt_mstr)
         abs_qty
         abs_site
         abs_loc
         abs_lotser
      with frame c.

      do on error undo, retry on endkey undo mainloop, retry mainloop
      with frame c:
/*GUI*/ if global-beam-me-up then undo, leave.


         set abs_item.

         new_site = abs_shipfrom.
         global_part = abs_item.

         {gprun.i ""gpptsi01.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


         if err_stat <> 0 then do:
            /* Item does not exist at site */
            {pxmsg.i &MSGNUM=715 &ERRORLEVEL=3}
            undo, retry.
         end.

         find pt_mstr where pt_part = abs_item no-lock no-error.
         if not available pt_mstr then do:
            /* Not a valid item */
            {pxmsg.i &MSGNUM=16 &ERRORLEVEL=3}
            undo, retry.
         end.

         if new abs_mstr then do:
            assign
               abs_site = abs_shipfrom
               abs_loc = pt_loc.

            display
               abs_site
               abs_loc.
         end.

         display pt_desc1.

         global_part = abs_item.

         set
            abs_qty
            abs_site
            abs_loc
            abs_lotser
            abs_ref
         editing:
            assign
               global_site = input abs_site
               global_loc = input abs_loc
               global_lot = input abs_lotser.
            readkey.
            apply lastkey.
         end.

         /* ADDED UM CONV AS TENTH INPUT PARAMETER ; PASSING ZERO  */
         {gprun.i ""rcctmtb.p""
            "(input transtype,
              input abs_shipfrom,
              input abs_site,
              input abs_loc,
              input abs_item,
              input abs_lotser,
              input nullstr,
              input abs_qty,
              input pt_um,
              input 0,
              output undotran)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         if undotran then undo, retry.

      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      if new abs_mstr then do:
         assign
            abs_wt_um = pt_net_wt_um
            abs_vol_um = pt_dim_um
            abs_gwt = (if pt_ship_wt > pt_net_wt
            then pt_ship_wt else pt_net_wt) * abs_qty.
      end.

      abs_recid = recid(abs_mstr).

   end.
/*GUI*/ if global-beam-me-up then undo, leave.


   find abs_mstr where recid(abs_mstr) = abs_recid no-lock.

   assign
      old_nwt = abs_nwt
      old_gwt = abs_gwt
      old_vol = abs_vol.

   /* MAINTAIN CONTAINERS */
   {gprun.i ""reshmta.p"" "(input abs_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


   /* MAINTAIN ITEMS */
   {gprun.i ""reshmtb.p"" "(input abs_recid, input no)"}
/*GUI*/ if global-beam-me-up then undo, leave.


   /* UPDATE WEIGHTS AND VOLUME */
   {gprun.i ""rcshmtc.p"" "(input abs_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


   /* PROPAGATE CHANGE IN WEIGHTS OR VOL UP THRU PARENTS */
   diff_nwt = abs_nwt - old_nwt.
   diff_gwt = abs_gwt - old_gwt.
   diff_vol = abs_vol - old_vol.

   {gprun.i ""rcshmtd.p""
      "(input abs_shipfrom, input abs_par_id,
        input diff_nwt, input diff_gwt, input diff_vol)"}
/*GUI*/ if global-beam-me-up then undo, leave.


   /* GET ANY SPECIAL BARCODE DATA AND/OR TEXT */
   {gprun.i ""rcctmta.p"" "(input recid(abs_mstr))"}
/*GUI*/ if global-beam-me-up then undo, leave.


   assign global_recid = recid(abs_mstr).

end.
/*GUI*/ if global-beam-me-up then undo, leave.


if is_wiplottrace_enabled() then
   delete PROCEDURE h_wiplottrace_procs no-error.
if is_wiplottrace_enabled() then
   delete PROCEDURE h_wiplottrace_funcs no-error.
